$(function() {
	var shopData = {
		data: [
			{
				"premises_name":"泰安市奥林匹克花园小区",
				"building_num":"01",
				"unit":"01",
				"room_num":"101",
				"last_paydate":"2017-08-01",
				"property_month_fee":"50"
			},
			{
				"premises_name":"华新山水居",
				"building_num":"02",
				"unit":"02",
				"room_num":"202",
				"last_paydate":"2017-09-01",
				"property_month_fee":"30"
			},
		]
	};
	function shopModal() {
		var self = this;

		self.defaults = {
			activeIndex: 0,
			isAdd: false,
			isAllcheck: false,
			isCancle: true,
			initData: {
				premises_name:"华新房地产",
				building_num:"00",
				unit:"00",
				room_num:"000",
				last_paydate:"2000-00-00 00:00:00",
				property_month_fee:"0"
			}
		}
		self.listData = ko.observableArray(shopData.data);

		self.line = ko.observable(self.defaults.initData);


		self.lineClick = function(data, e) {
			var lineData = $.extend({}, self.defaults.initData, data);
			self.line(lineData);
			var index = $(e.target).closest("li").index();

			self.defaults.activeIndex = index;
			self.defaults.isAdd = false;
		}
		
	}
	ko.applyBindings(new shopModal());
	
	$('#reckon').click(function(){
		//进行非空验证，自动将日期改为1号，进行日期的对比校验，这三种行为。
		var ttv = $('#this_paydate').val();
		if(!ttv){
			UM.alert({
			    title: '缴至日期不能为空',
			    btnText: ["", "确定"],
			});
			return;
		}
		ttv2 = ttv.substring(0,7) + '-01';
		if(ttv != ttv2){
			$('#this_paydate').val(ttv2);
            UM.toast({
			    title: '友情提示：',
			    text: '物业费须按整月缴费，缴至日期已自动更改为1号!'
			});
		}
		var lpd = $('#last_paydate').val().replace(/-/g,'');
		var tpd = $('#this_paydate').val().replace(/-/g,'');
		if(tpd <= lpd){
			UM.alert({
			    title: '本次缴至日期必须大于上次缴至日期！',
			    btnText: ["", "确定"],
			});
			return;
		}

		//to do 进行缴至日期的上传和返回应缴金额。
		alert('可以进行缴费金额的计算');
		
	});
	
	//验证可否进行支付
	$('#submit').click(function(){
		if(!$('#should_pay').val()){
			UM.alert({
			    title: '应缴金额不能为空，请先计算应缴金额',
			    btnText: ["", "确定"],
			});
			return;
		}
		alert('可以提交支付');
		//to do 提交物业费的缴纳
		
	});
	
	
});
